import React, { useContext, useReducer } from 'react'

const initialState = { count: 0, msg: '哈哈' }

function reducer(state, action) {
  switch (action.type) {
    case 'increment':
      return {
        ...state,
        count: state.count + 1,
      }
    case 'decrement':
      return {
        ...state,
        count: state.count - 1,
      }
    default:
      throw new Error()
  }
}
export default function Test() {
  const [state, dispatch] = useReducer(reducer, initialState)
  return (
    <div>
      Test
      <p>{state.count}</p>
      <p>{state.msg}</p>
      <button
        onClick={() => {
          dispatch({ type: 'increment' })
        }}
      >
        +
      </button>
    </div>
  )
}
